//引入路由组件
// import Home from '@/pages/Home' 
//实现路由懒加载 
//1.这样写下方配置路由在component:Home 这么写就可以。
// const Home=()=>{
//     console.log(1111111)
//     return import('@/pages/Home')
// }
//2.下方简写
//component:()=>import('@/pages/Home'), 
import Search from '@/pages/Search'
import Login from '@/pages/Login'
import Register from '@/pages/Register'
import Detail from '@/pages/Detail'
import AddCartSuccess from '@/pages/AddCartSuccess'
import ShopCart from '@/pages/ShopCart'
import Trade from '@/pages/Trade'
import Pay from '@/pages/Pay'
import PaySuccess from '@/pages/PaySuccess'
import Center from '@/pages/Center'
//引入二级路由
import MyOrder from '@/pages/Center/myOrder'
import GroupOrder from '@/pages/Center/groupOrder'
export default [
    {
        name:'home',
        path:'/home',
        //路由懒加载（简写）
        component:()=>import('@/pages/Home'), 
        meta:{isShow:true}
    },
    {
        name:'search',
        path:'/search/:keyword?',//？params参数可传递也可以不传递
        component:Search,
        meta:{isShow:true}
    }
    ,
    {
        name:'login',
        path:'/login',
        component:Login,
        meta:{isShow:false}
    }
    ,
    {
        path:'/register',
        component:Register,
        meta:{isShow:false}
    },
    {
        name:'detail',
        path:'/detail/:skuid',
        component:Detail,
        meta:{isShow:true}
    },
    {
        //加入购物车路由路由
        name:'addcartsuccess',
        path:'/addcartsuccess',
        component:AddCartSuccess,
        meta:{isShow:true}
    },
    {
        //购物车路由
        name:'shopcart',
        path:'/shopcart',
        component:ShopCart,
        meta:{isShow:true}
    },
    {
        //结算路由
        name:'trade',
        path:'/trade',
        component:Trade,
        meta:{isShow:true},
        //路由独享守卫
        beforeEnter: (to, from,next) => {
            //从购物车来 放行
          if(from.path=='/shopcart'){
            next()
          }else{
            //中断当前导航
            next(false)
          }
        },
    },
    {
        //支付路由
        name:'pay',
        path:'/pay',
        component:Pay,
        meta:{isShow:true},
        //路由独享守卫
        beforeEnter: (to, from,next) => {
            //从提交订单来 放行
          if(from.path=='/trade'){
            next()
          }else{
            //中断当前导航
            next(false)
          }
        }
    },
    {
        //支付成功后跳转的路由
        name:'paysuccess',
        path:'/paysuccess',
        component:PaySuccess,
        meta:{isShow:true},
        //路由独享守卫
        beforeEnter: (to, from,next) => {
            //从支付来 放行
          if(from.path=='/pay'){
            next()
          }else{
            //中断当前导航
            next(false)
          }
        }
    },
    {
        //支付成功页面的查看订单
        name:'center',
        path:'/center',
        component:Center,
        meta:{isShow:true},
        //二级路由
        children:[
            {
                path:'myorder',
                component:MyOrder
            },
            {
                path:'grouporder',
                component:GroupOrder
            },
            //重定向：当路由访问/center时我们就给他展示myorder
            {
                path:'/center',
                redirect:'/center/myorder'
            }
        ]
    },
    //重定向，在项目跑起来的时候，默认访问/，定向到首页
    {
        path:'*',
        redirect:'/home'
    }

]